package com.autoswf.core
{
	import flexunit.framework.TestCase;

	public class LinkSpliceTest extends TestCase
	{
		private var link:LinkSplice;
		private var mockLink1:MockLink;
		private var mockLink2:MockLink;
		
		
		public function LinkSpliceTest(methodName:String=null)
		{
			super(methodName);
		}
		
		
		override public function setUp():void
		{
			mockLink1 = new MockLink("mockLink1");
			mockLink2 = new MockLink("mockLink2");
			link = new LinkSplice("testLink");
		}
		
		/** returning true does not stop propagation */
		public function testHook01():void
		{
			var obj:Object = {}
			link.addHook(Object, function(transport:Object):Boolean
			{
				return true;
			})
			
			link.addParentLink(mockLink1);
			link.sendUp(obj);
			assertNotNull("propogation was stopped", mockLink1.sendUpResult);
		}
		
		
		/** false stops propagation */
		public function testHook02():void
		{
			var obj:Object = {}
			link.addHook(Object, function(transport:Object):Boolean
			{
				return false;
			})
			
			link.addParentLink(mockLink1);
			link.sendUp(obj);
			assertNull("propogation was not stopped", mockLink1.sendUpResult);
		}

		
		/** undefined stops propagation */
		public function testHook03():void
		{
			var obj:Object = {}
			link.addHook(Object, function(transport:Object):void
			{
				
			})
			
			link.addParentLink(mockLink1);
			link.sendUp(obj);
			assertNull("propogation was not stopped", mockLink1.sendUpResult);
		}
		
		
		/** null stops propagation */
		public function testHook04():void
		{
			var obj:Object = {}
			link.addHook(Object, function(transport:Object):Object
			{
				return null;
			})
			
			link.addParentLink(mockLink1);
			link.sendUp(obj);
			assertNull("propogation was not stopped", mockLink1.sendUpResult);
		}

		
		/** returning an object passes that object up instead of the original object */
		public function testHook05():void
		{
			var obj:Object = {}
			var newObj:Object = {};
			link.addHook(Object, function(transport:Object):Object
			{
				return newObj;
			})
			
			link.addParentLink(mockLink1);
			link.sendUp(obj);
			assertStrictlyEquals("propogation was not stopped", newObj, mockLink1.sendUpResult.message);
		}
		
	}
}